package com.zhu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhu.domain.Warehouse;
import com.zhu.mapper.WarehouseMapper;
import com.zhu.model.warehouse.WarehouseSelectVM;
import com.zhu.service.WarehouseService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author JoyBoy
 * @since 2022-06-02
 */
@Service
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements WarehouseService {

    @Override
    public boolean saveWarehouse(Warehouse warehouse) {
        return this.save(warehouse);
    }

    @Override
    public boolean deleteWarehouse(Integer warehouseId) {
        return this.removeById(warehouseId);
    }

    @Override
    public List<Warehouse> getAllWarehouses() {
        return this.list();
    }

    @Override
    public Warehouse getByName(String warehouseName) {
        QueryWrapper<Warehouse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("warehouse_name", warehouseName);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<Warehouse> getByDim(WarehouseSelectVM model) {
        QueryWrapper<Warehouse> queryWrapper = new QueryWrapper<>();
        if (model.getWarehouseId() != null) {
            queryWrapper.eq("warehouse_id", model.getWarehouseId());
        }
        if (model.getWarehouseName() != null) {
            queryWrapper.like("warehouse_name", model.getWarehouseName());
        }
        return this.list(queryWrapper);
    }

    @Override
    public Warehouse getByWarehouseId(Integer warehouseId) {
        return this.getById(warehouseId);
    }

    @Override
    public boolean updateWarehouse(Warehouse warehouse) {
        return this.updateById(warehouse);
    }
}
